package cn.com.guage;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class MapTest {

	 public static void main(String[] args) {
		 
	        Map<String, Integer> map = new HashMap<>();
	        map.put("web", 1024);
	        map.put("database", 2048);
	        map.put("static", 5120);
	 
	        System.out.println("Java 8 forEach loop");
	        map.forEach((key, value) -> System.out.println("[Key] : " + key + " [Value] : " + value));
	 
	        System.out.println("for entrySet()");
	        for (Map.Entry<String, Integer> entry : map.entrySet()) {
	            System.out.println("[Key] : " + entry.getKey() + " [Value] : " + entry.getValue());
	        }
	 
	        System.out.println("Iterator");
	        Iterator iter = map.entrySet().iterator();
	        while (iter.hasNext()) {
	            Map.Entry entry = (Map.Entry) iter.next();
	            System.out.println("[Key] : " + entry.getKey() + " [Value] : " + entry.getValue());
	        }
	 
	    }
}

class Solution {
    public int singleNumber(int[] nums) {
        HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
        int result = 0;
        for(int i= 0;i<nums.length;i++){
         Integer value = map.get(nums[0]);
         if(value!=null){
             value = value + 1;
            map.put(nums[i],value);
         }else{
             map.put(nums[i],1);
         }
}
         for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
                   Integer temp = entry.getValue();
                   if("1".equals(temp)){
                	   result =  entry.getKey();
                   }
         }
		return result;
      
    }
}
